import { getMemberInfo } from '@/api/user.js'
import { updateStatus } from '@/api/online.js'
const state = {
  userInfo: {},
  bluetoothStatus: false,
  bluetoothObj: null,
  isWxPay: false,
}

const mutations = {
  // 用户信息
  SET_USER_INFO (state, info) {
    state.userInfo = info
  },
  // 修改蓝牙链接状态
  UPDATE_STATUS (state, status) {
    state.bluetoothStatus = status
		const data = {
			equipmentNo: uni.getStorageSync('equipmentNo'),
			status: status ? 1 : 2
		}
		// updateStatus(data).then(respanse => {
		// })
  },
  UPDATE_WXPAY (state, status) {
    state.isWxPay = status

  		// updateStatus(data).then(respanse => {
  		// })
  },
  // 蓝牙对象
  SET_BLUETOOTH_OBJ (state, Obj) {
    state.bluetoothObj = Obj
  }
}

const actions = {
  // get user info
  getUserInfo ({ commit }) {
    return new Promise((resolve, reject) => {
      getMemberInfo().then(respanse => {
        const userInfo = respanse.result
        commit('SET_USER_INFO', userInfo)
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
